//
//  SYNewFeatureCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/1/24.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "SYNewFeatureCell.h"

@interface SYNewFeatureCell()

@property (nonatomic , weak) UIImageView *newImage;

@property (nonatomic, weak)  SYNoHeightedButton *enterBtn;


@end

@implementation SYNewFeatureCell

-(void)setImageString:(NSString *)imageString
{
    _imageString = imageString;
    
    self.newImage.image = [UIImage imageNamed:imageString];
}
-(void)btnHiddenWithItem:(NSInteger)item count:(NSInteger)count
{
    if (item == count - 1) {
        self.enterBtn.hidden = NO;
    }else{
        self.enterBtn.hidden = YES;
    }
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self newImage];
        [self enterBtn];
    }
    return self;
}

-(UIImageView *)newImage
{
    if (_newImage == nil) {
        UIImageView *newImage = [[UIImageView alloc] init];
        [self.contentView addSubview:newImage];
        [newImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(self);
        }];
        _newImage = newImage;
    }
    return _newImage;
}


-(SYNoHeightedButton *)enterBtn
{
    if (_enterBtn == nil) {
        SYNoHeightedButton *enterBtn = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:enterBtn];
        [enterBtn setTitle:@"点击体验" forState:UIControlStateNormal];
        [enterBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        enterBtn.backgroundColor = zhidainMainColor;
        enterBtn.titleLabel.font = [UIFont systemFontOfSize:font16ScreenWRate *LKScreenW];
        enterBtn.layer.cornerRadius = 4;
        [enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@(rate375(-44)));
            make.height.equalTo(isPhoneX ? @(rateX812(42)) : @(rate750(42)));
            make.width.equalTo(@(rate375(200)));
            make.centerX.equalTo(self);
        }];
        [enterBtn addTarget:self action:@selector(enterBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _enterBtn = enterBtn;
    }
    return _enterBtn;
}

-(void)enterBtnClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(newFeatureCellEnterButtonClick)]) {
        [self.delegate newFeatureCellEnterButtonClick];
    }
}


@end
